<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <!-- react的根元素 插入一个根组件 -->
    <div id="example"></div>
</body>
</html>
<script src="./js/react.development.js"></script>
<script src="./js/react-dom.development.js"></script>
<script src="./js/babel.js"></script>
<script type="text/babel">
    class MyComponent extends React.Component{
        constructor(props)
        {
            super(props)

            this.state = {
                txtRef: React.createRef()
            }

            this.handleClick = this.handleClick.bind(this)
        }

        handleClick()
        {
            console.log(this.state.txtRef.current.value)
        }    

        render()
        {
            return(
                <div>
                    <h1>定义refs属性</h1>
                    <input type="text" ref={this.state.txtRef} />
                    <button onClick={this.handleClick}>获取文本框的值</button>
                </div>
            )
        }
    }

    ReactDOM.render(
        <MyComponent />,
        document.getElementById('example')
    )
</script>